﻿@inject IEventService _eventService
@inject IDataCacheService _dataCacheService

<CnGalWebSite.Shared.MasaComponent.PC.Entries.Templates.OfficialWebsite.Others.CarouselsCard Model="Model" />
<CnGalWebSite.Shared.MasaComponent.PC.Entries.Templates.OfficialWebsite.Others.CarouselsCard Model="Model" Background />

<section id="top">
    @if (string.IsNullOrWhiteSpace(Model.WebsiteAddInfor?.FirstPage))
    {
        <div class="logo-area">
            <h1>
                @if (string.IsNullOrWhiteSpace(Model.WebsiteAddInfor?.Logo))
                {
                    <span>@Model.Name</span>
                }
                else
                {
                    <img width="100%" src="@Model.WebsiteAddInfor.Logo" />
                }
            </h1>
            @if (string.IsNullOrWhiteSpace(Model.WebsiteAddInfor?.SubTitle) == false)
            {
                <div class="lead">
                    @((MarkupString)Model.WebsiteAddInfor.SubTitle)
                </div>
            }
            else
            {
                <div class="lead">@publishTime</div>
            }

        </div>
        @if (string.IsNullOrWhiteSpace(Model.WebsiteAddInfor?.Impressions) == false)
        {
            <div class="copy">
                @((MarkupString)Model.WebsiteAddInfor.Impressions)
            </div>
        }
        <div class="button-area">
        @if (Model.Booking != null && Model.Booking.Open)
        {
                <BookingButton Template="EntryStyleTemplate.OfficialWebsite" Id="Model.Id" />
        }
        @if (Model.Releases.Any(s=>s.PublishPlatformType== PublishPlatformType.Steam))
        {
                <CnGalWebSite.Components.Buttons.MasaButton XLarge="@(_dataCacheService.IsApp?false:true)" Rounded Icon="@IconType.Steam.ToIconString()" Text="Steam商店" Href="@($"https://store.steampowered.com/app/{Model.Releases.FirstOrDefault(s=>s.PublishPlatformType== PublishPlatformType.Steam)?.Link}")" Target="_blank"/>
        }
    </div>
    }
    else
    {
        @((MarkupString)Model.WebsiteAddInfor.FirstPage)
    }
    
    @if (Model.WebsiteAddInfor == null)
    {
        <div class="infor">
            <CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaAlert Type="AlertTypes.Info" Class="ma-3" Transparent="false">
                未适配该词条，当前界面样式可能不美观，我们将会持续推进样式适配，尽情期待
            </CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaAlert>
        </div>
    }
</section>

@code {
    [Parameter]
    public EntryIndexViewModel Model { get; set; }

    string publishTime { get; set; }

    protected override void OnInitialized()
    {
        var release = Model.Releases.Where(s=>s.Type== GameReleaseType.Official).OrderBy(s => s.Time).FirstOrDefault(s => s.Time != null || string.IsNullOrWhiteSpace(s.TimeNote) == false);
        if(release==null)
        {
            publishTime = null;
            return;
        }
        if(string.IsNullOrWhiteSpace(release.TimeNote)==false)
        {
            publishTime = release.TimeNote;
            return;
        }

        if(release.Time!=null)
        {
            publishTime = release.Time.Value.ToString("yyyy年M月d日");
            return;
        }

    }
}
